import tornado.websocket
import tornado.escape
from tornado import web
import random,traceback
import json
import yaml,copy
import sys,os



z=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(z)
sys.path.append(z)
from _base_tool.python.lhp_deepcopy2 import lhp_deepcopy2,lhp_delete2

    #   "data_type":"set_list",//类型 修改数据
    #   update_params:[
    #     {//将路径为path的数据 进行 +1操作 并且存入属性add中 提供给data里面携带@add的属性调用
    #       name:'@add_idx',
    #       path:'page_config.'+this.window_var_path[1]+'.page_base_info.page_idx',//数据路径
    #       use:'++'
    #     }
    #   ],
    #   "postput":[
    #     {
    #       'path':'page_config.'+this.window_var_path[1]+'.page_base_info',
    #       'data':{//要更新的数据
    #           "page_idx": "@add_idx",
    #       }
    #     },
    #   ],
#将obj2里面的参数写入到obj中
# obj={'key1':'@add',"@add":{"1":{"@add":"@add",'f':[1,2,3,{'1':{'dd':'@add'}},'@add']}}}
# obj2={"@add":'123'}
# {'key1': '123', '123': {'1': {'f': [1, 2, 3, {'1': {'dd': '123'}}, '123'], '123': '123'}}}
def replacexxxWithXXX(obj,obj2):
    t_keys=list(obj2.keys())
    for key in t_keys:
        if '@'not in key:
            t_value=obj2[key]
            del obj2[key]
            obj2['@'+str(key)]=t_value
    if not isinstance(obj,(list,dict)) and obj in obj2:return obj2[obj]
    stack = [[]]#初始化栈，将根对象入栈  
    while (len(stack) > 0): 
        new_stack=[]
        while (len(stack) > 0):
            obj_path = stack.pop(); # 弹出栈顶元素 
            temp_obj=obj
            for _i in range(len(obj_path)-1):
                _path=obj_path[_i]
                if isinstance(temp_obj,list):_path=int(_path)
                temp_obj=temp_obj[_path]
            last_path=None
            if len(obj_path)>0:
                last_path=obj_path[-1]
                temp_obj2=temp_obj[last_path]
            else:
                temp_obj2=obj
            #如果待处理目标为dict 那么遍历key和value 替换key和value并将 list或dict类型的value存入stack中
            if isinstance(temp_obj2,dict):
                t_keys=list(temp_obj2.keys())
                for key in t_keys:
                    if isinstance(key,str) and '@'in key and key in obj2:
                        #记录值 删除旧key 添加新key
                        temp_value=copy.copy(temp_obj2[key])
                        del temp_obj2[key]
                        key=obj2.get(key)
                        temp_obj2[key]=temp_value
                    t_value=temp_obj2[key]
                    if isinstance(t_value,(list,dict)):
                        new_stack.append(obj_path+[key])
                    elif isinstance(t_value,str) and '@'in t_value and t_value in obj2:
                        temp_obj2[key]=copy.copy(obj2.get(t_value))
            #如果待处理目标为list 那么遍历value 替换value并将 list或dict类型的value存入stack中
            elif isinstance(temp_obj2,list):
                for _i in range(len(temp_obj2)):
                    temp_val2=temp_obj2[_i]
                    if isinstance(temp_val2,(list,dict)):
                        new_stack.append(obj_path+[_i])
                    elif isinstance(temp_val2,str) and '@' in temp_val2 and temp_val2 in obj2:
                         temp_obj2[_i]=copy.copy(obj2.get(temp_val2))
            elif  isinstance(temp_obj2,str) and'@'in temp_obj2:
                if temp_obj2 in obj2 and temp_obj2 in obj2:
                    if last_path is None:return copy.copy(obj2.get(temp_obj2))
                    else:
                        temp_obj[last_path]=copy.copy(obj2.get(temp_obj2))
        stack=new_stack
    return obj

def replacexxxWithXXX2(path1,obj2):

    for key in obj2:
        if key in path1:
            path1=path1.replace(key,obj2[key])
    return path1
# obj={'key1':'@add',"@add":{"1":{"@add":"@add",'f':[1,2,3,{'1':{'dd':'@add'}},'@add']}}}
# obj2={"@add":'123'}
# print(replacexxxWithXXX(obj,obj2))
class lhp_set_config_websocket_set_data:
    @classmethod
    #根据路径深拷贝对象
    def lhp_deepcopy2(cls,a:dict,path:str,__b):
        
        __b=copy.copy(__b)
        path_lst=path.split(".")
        for i in range(len(path_lst)-1):
            if isinstance(a,list):
                a=a[int(path_lst[i])]
            else:
                a=a[path_lst[i]]
        if isinstance(a,list):
            stack=[[int(path_lst[-1])]]#a的路径
        else:
            stack=[[path_lst[-1]]]#a的路径
        # print("stack:",stack)
        while  len(stack):
            a_path=stack.pop(0)
            temp_a=a
            temp_b=__b
            for i in range(len(a_path)-1):
                if isinstance(temp_a,list):
                    temp_a=temp_a[int(a_path[i])]
                else:
                    temp_a=temp_a[a_path[i]]
            for i in range(1,len(a_path)):
                if isinstance(temp_b,list):
                    temp_b=temp_b[int(a_path[i])]
                else:
                    temp_b=temp_b[a_path[i]]
            
            last_a_path=a_path[-1]
            if isinstance(temp_a,list):last_a_path=int(last_a_path)
            if isinstance(temp_a,dict):
                #存在这个key
                if last_a_path in temp_a:
                    if not isinstance(temp_a[last_a_path],(list,dict)):
                        temp_a[last_a_path]=temp_b
                    #判断值是否是字典 是则遍历字典 并且添加进待处理列表中
                    if isinstance(temp_b,dict) and isinstance(temp_a[last_a_path],dict):
                        for key in temp_b:
                            stack.append(a_path+[key])
                    #判断值是否是列表 是则遍历列表 并且添加进待处理列表中
                    elif isinstance(temp_b,list) and isinstance(temp_a[last_a_path],list):
                        for i in range(len(temp_b)):
                            stack.append(a_path+[i])
                    #不为列表也不为字典 直接赋值操作
                    else:
                        temp_a[last_a_path]=temp_b
                #不存在这个key 直接赋值操作
                else:
                    temp_a[last_a_path]=temp_b
            elif isinstance(temp_a,list):
                lenx=len(temp_a)
                #存在这个索引
                if last_a_path<lenx:
                    #判断值是否是字典 是则遍历字典 并且添加进待处理列表中
                    if isinstance(temp_b,dict):
                        for key in temp_b:
                            stack.append(a_path+[key])
                    #判断值是否是列表 是则遍历列表 并且添加进待处理列表中
                    elif isinstance(temp_b,list):
                        for i in range(len(temp_b)):
                            stack.append(a_path+[i])
                    #不为列表也不为字典 直接赋值操作
                    else:
                        temp_a[last_a_path]=temp_b
                
                #不存在这个索引 直接赋值操作
                else:
                    temp_a.append(temp_b)


    @classmethod
    def postput(cls,obj):
        try:
            cls.lhp_deepcopy2(obj.get("data"),obj.get("path"),obj.get("copy_data"))
            
            return {"type":'ok'}
        except Exception as e:
            return {"type":'error',"message":"lhp_set_config_websocket_set_data postput异常"+str(e)}
    @classmethod
    def delete(cls,obj={}):
        try:
            change_obj=obj.get("data")
            if '.'in obj.get("path"):
                path_lst=obj.get("path").split(".")
                if (len(path_lst)<=1):
                    return {"type":'error',"message":"delete异常 path路径数量小于等于1"}
                for i in range(len(path_lst)-1):
                    if isinstance(change_obj,list):
                        change_obj=change_obj[int(path_lst[i])]
                    else:
                        change_obj=change_obj[path_lst[i]]
                last_path=path_lst[-1]
                if isinstance(change_obj,dict):
                    try:
                        del change_obj[last_path]
                    except:
                        # print("path_lst",path_lst)
                        del change_obj[int(last_path)]
                elif isinstance(change_obj,list):
                    del change_obj[int(last_path)]
            else:
                if isinstance(change_obj,dict):
                    try:
                        del change_obj[obj.get("path")]
                    except:
                        del change_obj[int(obj.get("path"))]
                elif isinstance(change_obj,list):
                    del change_obj[int(obj.get("path"))]
            return {"type":'ok'}

        except Exception as s:
            print(str(traceback.print_exc()))
            return {"type":'error',"message2":"lhp_set_config_websocket_set_data delete异常"+str(s),"message":traceback.print_exc()}
    @classmethod
    def clear(cls,obj={}):
        try:
            change_obj=obj.get("data")
            if '.'in obj.get("path"):
                path_lst=obj.get("path").split(".")
                if (len(path_lst)<=1):
                    return {"type":'error',"message":"clear异常 path路径数量小于等于1"}
                for i in range(len(path_lst)-1):
                    if isinstance(change_obj,list):
                        change_obj=change_obj[int(path_lst[i])]
                    else:
                        change_obj=change_obj[path_lst[i]]
                last_path=path_lst[-1]
                if isinstance(change_obj,list):
                    last_path=int(last_path)
                change_obj2=change_obj[last_path]
                if isinstance(change_obj2,dict):
                    change_obj[last_path]={}
                elif isinstance(change_obj2,list):
                    change_obj[last_path]=[]
                elif isinstance(change_obj2,str):
                    change_obj[last_path]=''
                elif isinstance(change_obj2,int):
                    change_obj[last_path]=0
                elif isinstance(change_obj2,bool):
                    change_obj[last_path]=False

            else:
                return {"type":'error',"message":"clear异常 path路径数量小于2"}
            return {"type":'ok'}

        except Exception as s:
            return {"type":'error',"message":"lhp_set_config_websocket_set_data clear异常"+str(s)}
    @classmethod
    def insert(cls,obj={}): 
        try:
            path=obj.get("path")
            path_lst=path.split(".")
            before_idx=obj.get("before_idx")#;//要插入到第几个元素之前
            change_obj=obj.get("data")#;//要插入的数据
            copy_data=obj.get("copy_data")
            if (len(path_lst)<=1):
                return {"type":'error',"message":"insert异常 数量小于等于1"}
            
            for i in range(len(path_lst)):
                if isinstance(change_obj,list):
                    change_obj=change_obj[int(path_lst[i])]
                else:
                    change_obj=change_obj[path_lst[i]]
            if before_idx is None:
                change_obj.append(copy.copy(copy_data))
            else:
                if isinstance(change_obj,dict):
                    change_obj[before_idx]=copy.copy(copy_data)
                elif isinstance(change_obj,list):
                    before_idx=int(before_idx)
                    if before_idx>=len(change_obj):
                        change_obj.append(copy.copy(copy_data))
                    else:
                        change_obj.insert(before_idx,copy.copy(copy_data))
            return {"type":'ok'}

        except Exception as e:
            
                            
            # 打印错误类型和错误信息  
            print(f"set_list insert发生错误: {type(e).__name__}, {e}")  
            # 打印完整的错误跟踪信息  
            traceback.print_exc()
            return {"type":'error',"message":"lhp_set_config_websocket_set_data insert异常"+str(e)}
# 读取YAML文件  
def read_yaml(file_path):  
    with open(file_path, 'r',encoding='utf-8') as file:  
        data = yaml.safe_load(file)  
    return data
num_dct={}

class auto_config:
    def __init__(self,kwargs):
        self.user_dir=os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+os.sep+"user_dir"
        #存放所有正在编辑的项目 user_id=1&project_dir=0&project_id=1
        #{("1","1","1 "):{"users":[],"info":{}}}
        global num_dct
        self.num_dct=num_dct
        self.check_user_login_data=kwargs['check_user_login_data']#判断用户 登录是否合法
        self.check_user_project_edit=kwargs['check_user_project_edit']#判断用户 是否可以对项目进行处理
        # self.return_edit_data=kwargs['edit_data']#返回编辑数据
    def add_edit(self,web_socket_obj,easyedit_userid,user_id,project_dir,project_id):
        try:
            #验证用户是否有编辑权限
            edit_flag=self.check_user_project_edit(easyedit_userid,user_id,project_dir,project_id)
            # print("edit_flag",edit_flag)
            if edit_flag is False:return

            key=(str(user_id),str(project_dir),str(project_id))
            #初始化参数列表
            if self.num_dct.get(key)is None:
                self.num_dct[key]={"users":[web_socket_obj.num],"info":{}}
                with open(os.path.join(self.user_dir,user_id,"self",project_dir,"projects",project_id,"main.yaml"), 'r',encoding='utf-8') as file:  
                    self.num_dct[key]['info']=yaml.safe_load(file)  
            else:
                self.num_dct[key]['users'].append(web_socket_obj.num)
            web_socket_obj.now_edit=key
            return self.num_dct[key]['info']
        except:
            print(str(traceback.print_exc()))
    def check_edit(self,web_socket_obj,easyedit_userid,user_id,project_dir,project_id):
        #验证用户是否有编辑权限
        edit_flag=self.check_user_project_edit(easyedit_userid,user_id,project_dir,project_id)
        if edit_flag is False:return False
        return True
    def del_edit(self,web_socket_obj):
        key=web_socket_obj.now_edit
        #移除当前正在参与的项目
        self.num_dct[key]['users'].remove(web_socket_obj.num)
        #如果当前参与这个项目的人员为空 则删除项目
        if len(self.num_dct[key])==0:
            del self.num_dct[key]
        web_socket_obj.now_edit=None
    def open(self,web_socket_obj):
        web_socket_obj.now_edit=None
    def on_message2(self,web_socket_obj,message,key,objs__):
        data_type=message.get("data_type")
        if (data_type=="postput"):
            path_val=message.get("path")
            data_val=message.get("data")
            #修改服务端数据
            res=lhp_set_config_websocket_set_data.postput({
            "data":self.num_dct[key]["info"],
            "path":path_val,
            "copy_data":data_val,
            })
            # print("postput 服务端完成")
            #修改异常则跳过后续 回复当前操作对象操作失败
            if (res['type']=='error'):web_socket_obj.write_message(json.dumps(res));return None
            # 同步其他客户端数据
            #同步到所有正在编辑当前项目的用户中 
            send_message=json.dumps(message)
            for _num_ in objs__:
                # if _num_ !=web_socket_obj.num:
                web_socket_obj.return_client_by_num(_num_)['client'].write_message(send_message)
        
            # print("postput 回复客户端完成")
        elif(data_type=="delete"):
            
            path_val=message.get("path")
            #修改服务端数据
            res=lhp_set_config_websocket_set_data.delete({
                "data":self.num_dct[key]["info"],
                "path":path_val,
                })
            #修改异常则跳过后续 回复当前操作对象操作失败
            if (res['type']=='error'):web_socket_obj.write_message(json.dumps(res));return None
            # 同步其他客户端数据
                #同步其他客户端数据
            send_message=json.dumps(message)
            for _num_ in objs__:
                # if _num_ !=web_socket_obj.num:
                web_socket_obj.return_client_by_num(_num_)['client'].write_message(send_message)
        elif(data_type=="clear"):
            
            path_val=message.get("path")
            #修改服务端数据
            res==lhp_set_config_websocket_set_data.clear({
                    "data":self.num_dct[key]["info"],
                    "path":path_val,
                })
            #修改异常则跳过后续 回复当前操作对象操作失败
            if (res['type']=='error'):web_socket_obj.write_message(json.dumps(res));return None
            # 同步其他客户端数据
            send_message=json.dumps(message)
            for _num_ in objs__:
                # if _num_ !=web_socket_obj.num:
                web_socket_obj.return_client_by_num(_num_)['client'].write_message(send_message)
        elif(data_type=='set_list'):
            set_list_params={}
            try:
                update_params=message.get("update_params")
                if(update_params is not None and len(update_params)>0):
                    # // params:[
                    # //     {//将路径为path的数据 进行 +1操作 并且存入属性add中 提供给data里面携带@add的属性调用
                    # //       name:'add_idx',
                    # //       path:'page_config.'+this.window_var_path[1]+'.'+page_base_info+'.page_idx',//数据路径
                    # //       use:'++'
                    # //     }
                    # //   ],
                    # print("set_list_params 处理前:",update_params)
                    #首先 对params里面的数据进行计算  如对path为xxx的值进行++操作然后存入params中
                    #遍历原列表
                    for t_obj in update_params:
                        # print('1')
                        use=t_obj['use']
                        name=t_obj['name']
                        path=t_obj['path']
                        # print('2')
                        edit_data=self.num_dct[key]["info"]
                        # print('3',edit_data['page_config'],path)
                        not_find=True
                        try:
                            for tp_idx in path.split("."):
                                if isinstance(edit_data,list):
                                    edit_data=edit_data[int(tp_idx)]
                                else:
                                    edit_data=edit_data[tp_idx]
                        except Exception as e:
                            
                            print('8',traceback.print_exc())
                            not_find=False
                            print("err",str(e))
                        # print('4')
                        #如果是计数加一则
                        if use=='++':
                            set_list_params[name]=int(edit_data)+1
                        elif use=='++s':
                            set_list_params[name]=str(int(edit_data)+1)
                        elif use=="check_true": 
                            if (not_find is True):
                                web_socket_obj.write_message(json.dumps({"type":"error","message":t_obj.get("message")}));return None
                        else:
                            set_list_params[name]=copy.copy(edit_data)
                    # print("set_list_params 处理后:",set_list_params)
                    set_list_params2={key_:set_list_params[key_]for key_ in set_list_params}
                    # try:
                    #     self.num_dct[key]["info"]['page_config'][0]['page_base_info']
                    # except:
                    #     print("err xx1")
                    #将待处理对象 替换为 params里面的值
                    for data_type in {'postput','insert','delete','clear'}:
                        try:
                            if message.get(data_type) is not None:
                                # print('start data_type:',data_type,message[data_type])
                                # print("set_list_params2",set_list_params2)
                                for tp_idx3 in range(len(message[data_type])):
                                    message[data_type][tp_idx3]['path']=replacexxxWithXXX2(message[data_type][tp_idx3]['path'],set_list_params2)
                                    replacexxxWithXXX(message[data_type][tp_idx3]['data'],set_list_params)
                                # print('end data_type:',data_type,message[data_type])
                        except:
                            
                            # 打印完整的错误跟踪信息  
                            print("9",traceback.print_exc())
                        try:
                            if message.get('other_callback')is not None:
                                replacexxxWithXXX(message['other_callback'],set_list_params)
                        except:
                            # 打印完整的错误跟踪信息  
                            print("10",traceback.print_exc())
                #将数据写入到服务端的配置文件中
                try:
                    
                    if message.get('delete'):
                        del_info=self.num_dct[key]["info"]
                        for temp_idx in range(len(message['delete'])):
                            res=lhp_set_config_websocket_set_data.delete({
                                "data":del_info,
                                "path":message['delete'][temp_idx]['path'],
                            })
                            if (res['type']=="error"):
                                web_socket_obj.write_message(json.dumps(res));return None
                except:
                    
                    print('7',traceback.print_exc())
                # delete2:[
                #     {
                #         'delete_before':"xxxxx",
                #         "lst":['x']
                #     }
                # ]
                #将数据写入到服务端的配置文件中
                try:
                    if message.get('delete2'):
                        for item in message['delete2']:
                            del_info=self.num_dct[key]["info"]
                            delete_before=item.get("delete_before")
                            if delete_before is not None:
                                path_lst=item.get("delete_before").split(".")
                                for i in range(len(path_lst)):
                                    if isinstance(del_info,list):
                                        del_info=del_info[int(path_lst[i])]
                                    else:
                                        del_info=del_info[path_lst[i]]
                            for item2 in item['lst']:
                                res=lhp_set_config_websocket_set_data.delete({
                                    "data":del_info,
                                    "path":item2,
                                })
                                if (res['type']=="error"):
                                    web_socket_obj.write_message(json.dumps(res));return None
                except:
                    
                    print('11',traceback.print_exc())
                try:
                    if message.get('clear'):
                        for temp_idx in range(len(message['clear'])):
                            res=lhp_set_config_websocket_set_data.clear({
                                "data":self.num_dct[key]["info"],
                                "path":message['clear'][temp_idx]['path'],
                            })
                            if (res['type']=="error"):
                                web_socket_obj.write_message(json.dumps(res));return None

                except:
                    
                    print('12',traceback.print_exc())

                try:
                    if message.get('postput') is not None:
                        for temp_idx in range(len(message['postput'])):
                            dddddata={
                                "data":self.num_dct[key]["info"],
                                "path":message['postput'][temp_idx]['path'],
                                "copy_data":message['postput'][temp_idx]['data'],
                            }
                            # print("---post data",dddddata)
                            res=lhp_set_config_websocket_set_data.postput(dddddata)
                            if(message['postput'][temp_idx].get("other_info")):
                                res['other_info']=message['postput'][temp_idx]['other_info']
                            if (res['type']=="error"):
                                web_socket_obj.write_message(json.dumps(res));return None
                        # print("start postput 2222")
                except Exception as e:
                    
                    print('4',traceback.print_exc())
                    # 打印错误类型和错误信息  
                    print(f"set_list postput发生错误: {type(e).__name__}, {e}")  
                    # 打印完整的错误跟踪信息  
                    traceback.print_exc()
                # try:
                #     self.num_dct[key]["info"]['page_config'][0]['page_base_info']
                # except:
                #     print('3',traceback.print_exc())
                #     print("err xx5")
                try:
                    if message.get('insert') is not None:
                        for temp_idx in range(len(message['insert'])):
                            res=lhp_set_config_websocket_set_data.insert({
                                "data":self.num_dct[key]["info"],
                                "path":message['insert'][temp_idx]['path'],
                                "before_idx":message['insert'][temp_idx]['before_idx'],
                                "copy_data":message['insert'][temp_idx]['data'],
                            })
                            if (res['type']=="error"):
                                web_socket_obj.write_message(json.dumps(res));return None
                except Exception as e:
                    
                    # 打印错误类型和错误信息  
                    print(f"set_list insert发生错误: {type(e).__name__}, {e}")  
                    # 打印完整的错误跟踪信息  
                    print("13",traceback.print_exc())
                # try:
                #     self.num_dct[key]["info"]['page_config'][0]['page_base_info']
                # except:
                #     print('2',traceback.print_exc())
                #     print("err xx6")
                
                #同步其他客户端数据
                send_message=json.dumps(message)
                for _num_ in objs__:
                    web_socket_obj.return_client_by_num(_num_)['client'].write_message(send_message)   
                
                # try:
                #     self.num_dct[key]["info"]['page_config'][0]['page_base_info']
                # except:
                #     print('1',traceback.print_exc())
                #     print("err xx7")
            except:
                print('0',traceback.print_exc())
        print("websocket结束消息处理")    
    #同步数据
    def on_message(self,web_socket_obj,message:dict):
        print("websocket接收消息")
        if message.get('template_name')=="lhp_set_config_____1":
            # print("num_dct",num_dct)
            easyedit_userid = str(web_socket_obj.get_cookie("easyedit_userid"))
            easyedit_token = str(web_socket_obj.get_cookie("easyedit_token"))
            easyedit_loginip=web_socket_obj.get_ip()#获取登录时的ip
            login_flag,login_info= self.check_user_login_data(easyedit_userid,easyedit_token,easyedit_loginip)
            if login_flag is False:return
            # print("message",message)
            #配置处理

            message_type=message.get("type")
            params_=message.get("params")
            #当前 用户 申请编辑配置
            if message_type=='regist':
                #注册配置数据 
                if params_.get("regist_type")=="project":
                    #获取项目配置
                    user_id=str(params_.get("user_id"))
                    project_dir=str(params_.get("project_dir"))
                    project_id=str(params_.get("project_id"))
                    key=(user_id,project_dir,project_id)
                    #注销之前参与的项目
                    if (web_socket_obj.now_edit is not None):
                        self.del_edit(web_socket_obj)
                    edit_data=self.add_edit(web_socket_obj,easyedit_userid,user_id,project_dir,project_id)
                    if edit_data is not None:
                        # 向客户端发送消息  #返回成功
                        web_socket_obj.write_message(json.dumps(
                            {"type":"change_data","data_type":"postput","path":"","data":edit_data}
                            
                            )  )
                    else:
                        print(edit_data)
                        web_socket_obj.write_message(json.dumps({"type":"error","message":"用户验证不通过1.1"}))
                #返回编辑数据
                # elif params_.get("regist_type")=="edit":
                #     web_socket_obj.write_message(
                        
                #             {"type":"change_data","data_type":"postput","path":"","data":self.return_edit_data( )}
                #        )
            elif (message_type=="change_data"):
                # print("change_data 1")
                key=web_socket_obj.now_edit
                user_id,project_dir,project_id=key
                edit_flag=self.check_edit(web_socket_obj,easyedit_userid,user_id,project_dir,project_id)
                if edit_flag is None:
                    web_socket_obj.write_message(json.dumps({"type":"error","message":"用户验证不通过2"}))
                    return
                objs__=self.num_dct[key]["users"]
                self.on_message2(web_socket_obj,message,key,objs__)
                

        #注销对象
    def on_close(self,web_socket_obj,):
        self.del_edit(web_socket_obj)
# {
#     "type": "change_data",
#     "data_type": "set_list",
#     "update_params": [
#         {
#             "name": "add_idx",
#             "path": "page_config.0.page_base_info.page_idx",
#             "use": "++"
#         }
#     ],
#     "postput": [
#         {
#             "path": "page_config.0.page_base_info",
#             "data": {
#                 "page_idx": "@add_idx"
#             }
#         }
#     ],
#     "insert": [
#         {
#             "path": "page_config.0.page_use_compontent.page.child.0.child",
#             "before_idx": null,
#             "data": {
#                 "ch_name": "基础侧边栏1",
#                 "use_compontent": "cebianlan1",
#                 "data": {
#                     "var_name": "",
#                     "width": "auto",
#                     "height": "100%",
#                     "data": [
#                         {
#                             "name": "控制系统",
#                             "icon": "icon-kongzhitai",
#                             "click_func": ""
#                         },
#                         {
#                             "name": "控制中心",
#                             "icon": "icon-kongzhitai",
#                             "click_func": ""
#                         },
#                         {
#                             "name": "工艺设定",
#                             "icon": "icon-tree_main_factory",
#                             "click_func": ""
#                         },
#                         {
#                             "name": "产品库1",
#                             "icon": "icon-pinzhong",
#                             "click_func": ""
#                         },
#                         {
#                             "name": "产品库2",
#                             "icon": "icon-huabi",
#                             "click_func": ""
#                         },
#                         {
#                             "name": "用户中心",
#                             "icon": "icon-yonghu",
#                             "click_func": ""
#                         },
#                         {
#                             "name": "日志中心",
#                             "icon": "icon-rizhi",
#                             "click_func": ""
#                         }
#                     ]
#                 },
#                 "idx": "@add_idx",
#                 "child": []
#             }
#         }
#     ],
#     "other_callback": [
#         {
#             "key": "set_dom",
#             "data": {
#                 "father_path": [
#                     0
#                 ],
#                 "father_idx": 1,
#                 "before_idx": null,
#                 "update_idx": "@add_idx",
#                 "add_params": {
#                     "type": true,
#                     "k": "基础侧边栏1",
#                     "v": {
#                         "ch_name": "基础侧边栏1",
#                         "name": "cebianlan1",
#                         "data": {
#                             "var_name": {
#                                 "ch_name": "全局变量名",
#                                 "default": "",
#                                 "type": "text",
#                                 "notes": "组件属性可以通过全局进行访问"
#                             },
#                             "width": {
#                                 "ch_name": "宽[width]",
#                                 "default": "auto",
#                                 "type": "text",
#                                 "notes": "骨架的宽度"
#                             },
#                             "height": {
#                                 "ch_name": "高[height]",
#                                 "default": "100%",
#                                 "type": "text",
#                                 "notes": "骨架的高度"
#                             },
#                             "data": {
#                                 "ch_name": "数据",
#                                 "type": "listdct",
#                                 "listdct": {
#                                     "name": {
#                                         "ch_name": "显示文本",
#                                         "default": "文本",
#                                         "type": "text",
#                                         "notes": "侧边框的文本格式"
#                                     },
#                                     "icon": {
#                                         "ch_name": "icon_class",
#                                         "defualt": "",
#                                         "type": "text",
#                                         "notes": "图标的class"
#                                     },
#                                     "click_func": {
#                                         "ch_name": "触发函数",
#                                         "default": "",
#                                         "type": "text",
#                                         "notes": "全局变量.xxx.xxx格式"
#                                     }
#                                 },
#                                 "notes": "只是在编辑状态下才会显示的条纹，设置是否关闭",
#                                 "default": [
#                                     {
#                                         "name": "控制系统",
#                                         "icon": "icon-kongzhitai",
#                                         "click_func": ""
#                                     },
#                                     {
#                                         "name": "控制中心",
#                                         "icon": "icon-kongzhitai",
#                                         "click_func": ""
#                                     },
#                                     {
#                                         "name": "工艺设定",
#                                         "icon": "icon-tree_main_factory",
#                                         "click_func": ""
#                                     },
#                                     {
#                                         "name": "产品库1",
#                                         "icon": "icon-pinzhong",
#                                         "click_func": ""
#                                     },
#                                     {
#                                         "name": "产品库2",
#                                         "icon": "icon-huabi",
#                                         "click_func": ""
#                                     },
#                                     {
#                                         "name": "用户中心",
#                                         "icon": "icon-yonghu",
#                                         "click_func": ""
#                                     },
#                                     {
#                                         "name": "日志中心",
#                                         "icon": "icon-rizhi",
#                                         "click_func": ""
#                                     }
#                                 ]
#                             }
#                         }
#                     },
#                     "name": "cebianlan1",
#                     "_type_val": "zj"
#                 }
#             }
#         }
#     ],
#     "params": {
#         "user_id": "1",
#         "project_dir": "0",
#         "project_id": "1",
#         "regist_type": "project"
#     },
#     "template_name": "lhp_set_config_____1"
# }
